<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2016/1/14
 * Time: 11:06
 */

class Involved_SpecModel extends BaseModel{

    protected $table = 'spec';

    /**********************   APP接口   ******************/


    /**
     * 获取材质规格
     * @param $cate_id
     * @return mixed
     */
    public function GetSpecList($cate_id)
    {
        return  DB::table($this->table)
                ->selectRaw('spec_id as id,spec_name as name')
                ->where('quality',$cate_id)
                ->get();
    }


    /**********************   PC接口   ******************/


    /**
     * 展示规格
     * @return mixed
     * @author alice
     * @date 2016-1-25
     */
    public function ShowSpecList()
    {
        return DB::table($this->table)->paginate(10);
    }

    /**
     * 展示规格信息
     * @param $id
     * @return mixed
     * @author alice
     * @date 2016-1-25
     */
    public function GetSpecInfo($id)
    {
        return DB::table($this->table)
                ->where('spec_id',$id)
                ->first();
    }

    /**
     * 获取规格名称
     * @param $spec_id
     * @return mixed
     */
    public function GetSpecNameById($spec_id)
    {
        $spec  = $this->GetSpecInfo($spec_id);
        return ($spec && property_exists($spec,'spec_name')) ? $spec->spec_name : "未知";
    }

}